/**
 * 初始化
 */
$(document).ready(function(){
	$("#recoverPwdUpdate").click(function(){
		if(validataUname() && validataEmail()){
			var remoteTrans = new Helper.RemoteTrans({
				url:Helper.basePath+"/goPwdRecoverByEmail.htm",
				onError:function(json){
					alert(json.message);
				},
				onSuccess:function(json) {
					if(json.isSuccess){
						location.href=Helper.basePath+json.returnValue;
					}else{
						alert(json.message);
					}
				}
			});
			var pwdType=$("input[name='IpwdType']:checked").val();
			remoteTrans.params = {username:$("#username").val().trim(),email:$('#email').val(),pwdType:pwdType};
			remoteTrans.send();
		}
	});
	$("#xiugaimima").click(function(){
		if(validataPass() && validataPass1()){
			var remoteTrans = new Helper.RemoteTrans({
				url:Helper.basePath+"/doResetPwdForRecoverPwd.htm",
				onError:function(json){
					alert(json.message);
				},
				onSuccess:function(json) {
					if(json.isSuccess){
						if($("#3338login").val()==3338){
							location.href=Helper.basePath+"/page/3338web/findPwd_ok.jsp";
						}else{
							location.href=Helper.basePath+"/page/password/recover_ok.jsp";
						}
						
					}else{
						alert(json.message);
					}
				}
			});
			remoteTrans.params = {betCardNO:$("#IbetCardNO").val().trim()
					,newPassword:$('#password').val(),type:$("#Itype").val()
					,codeOrMessage:$("#Icode").val(),findType:$("#IfindType").val()};
			remoteTrans.send();
		}
	});
	
	var validataPass = function(){
		var text = $("#password");
		var message = Helper.validata.validataPass(text.val());
		if(message) {
			alert(message);
			return;
		}
		return true;
	};
	
	var validataPass1 = function(){
		var text = $("#password1");
		var val = text.val();
		var message = Helper.validata.validataPass(val);
		if(message) {
			alert("确认"+message);
			return;
		}
		if(val!==$("#password").val()) {
			alert("两次密码输入不一致");
			return;
		}
		return true;
	};
	
	var validataUname = function(){
		var text = $("#username");
		var message = Helper.validata.validataUname(text.val());
		if(message) {
			alert(message);
			return;
		}
		if(Helper.validata.isInteger(text.val())) {
			alert("用户名不能是纯数字");
			return;
		}
		return true;
	};
	
	var validataEmail = function(){
		var text = $("#email");
		var value = text.val();
		if(!Helper.isEmpty(value))
		{
			var message = Helper.validata.validataEmail(text.val());
			if(message) 
			{
				alert(message);
				return;
			}
		} 
		else 
		{
			alert("请输入电子邮箱");
			return;
		}
		return true;
	};
});